#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e3 + 10;
int a[N], b[N], c[N], d[N];
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; i++) cin >> a[i], c[i] = a[i];
		for (int i = 1; i <= n; i++) cin >> b[i], d[i] = b[i];
		sort(c + 1, c + n + 1);
		sort(d + 1, d + n + 1);
		bool flag = 0;
		for (int i = 1; i <= n; i++) {
			if (c[i] != d[i]) {
				flag = 1;
				break;
			}
		}
		if (flag) {
			cout << "NO" << endl;
			continue;
		}
		cout << "YES" << endl;
		for (int i = 1; i < n; i++) {
			int idx = 0;
			if (a[i] != b[i]) {
				for (int j = i; j <= n; j++) {
					if (a[j] == b[i]) {
						idx = j;
						break;
					}
				}
			}
			for (int j = idx; j > i; j--) {
				swap(a[j], a[j - 1]);
				cout << j << " " << j - 1 << endl;
			}
		}
		cout << 0 << " " << 0 << endl;
	}
	return 0;
}